home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / gs3.53 / wftopfa.ps < prev    next >
Text File  |  1996-01-10  |  9KB  |  305 lines

  1. %    Copyright (C) 1995 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % wftopfa.ps
  16. % Convert a Wadalab base font to .PFA (or .PFB) format.
  17.  
  18. (gs_ksb_e.ps) run
  19. (wrfont.ps) run
  20.  
  21. /wftopfa_dict 100 dict def
  22. wftopfa_dict begin
  23.  
  24. /KanjiSubEncoding dup .findencoding def
  25.  
  26. % Initialize parameters.
  27. /init            % - init -
  28.  { /chars 256 dict def
  29.    /version (001.001) def
  30.    /highcode 0 def
  31.    /StdHW [32] def
  32.    /StdVW [32] def
  33.    /UniqueID 20000000 def
  34.    /FontBase (Wadalab) def
  35.    /StdEncMode false def
  36.    /CustomEncMode false def
  37.    /Binary false def
  38.    /Encrypt true def
  39.  } bind def
  40.  
  41. % Read definitions.
  42. /rdstring 5000 string def
  43. /readdefs        % <filename> readdefs -
  44.  { (r) file
  45.     { dup rdstring readline not { pop exit } if
  46.       dup length 15 ge
  47.        { dup dup length 7 sub 7 getinterval (> CompD) eq
  48.       { token pop exch token pop exch pop
  49.         dup 0 get /highcode exch def
  50.         exch chars 3 1 roll put
  51.       }
  52.       { pop
  53.       }
  54.      ifelse
  55.        }
  56.        { pop
  57.        }
  58.       ifelse
  59.     }
  60.    loop closefile
  61.  } bind def
  62.  
  63. % Write out the final font.
  64. /writepfa
  65.  { 4 string highcode 16#1000 add 16 2 index cvrs 0 (.r) putinterval
  66.      FontBase exch concatstrings /fullname exch def
  67.    UniqueID 20000000 eq { /UniqueID 4990000 highcode add def } if
  68.    /encoding CustomEncMode
  69.     { KanjiSubEncoding }
  70.     { StdEncMode { StandardEncoding } { ISOLatin1Encoding } ifelse }
  71.    ifelse def
  72.  
  73.    /Font 30 dict def
  74.    Font begin
  75.    /FontInfo 20 dict def
  76.    FontInfo begin
  77.  
  78.         % Write the clear text part.
  79.  
  80.    /CreationDate (%Calendar%) currentdevparams
  81.      dup /Weekday get {(Sun )(Mon )(Tue )(Wed )(Thu )(Fri )(Sat )} exch get
  82.      1 index /Month get 1 sub
  83.        {(Jan)(Feb)(Mar)(Apr)(May)(Jun)(Jul)(Aug)(Sep)(Oct)(Nov)(Dec)} exch get
  84.      concatstrings
  85.       {{/Day ( )} {/Hour ( )} {/Minute (:)} {/Second (:)} {/Year ( )}}
  86.       { dup 1 get 3 -1 roll exch concatstrings exch
  87.         0 get 2 index exch get
  88.         dup 10 lt { =string cvs (0) exch concatstrings } { =string cvs } ifelse
  89.         concatstrings
  90.       }
  91.      forall exch pop readonly def
  92.    /VMusage 100000 def
  93.    /version version readonly def
  94.    /Notice (No copyright on this font. Original available from moe.ipl.t.u-tokyo.ac.jp:/Font. Converted by wftopfa.ps (Aladdin Enterprises).) readonly def
  95.    /FullName fullname readonly def
  96.    /FamilyName FontBase readonly def
  97.    /Weight (Regular) readonly def
  98.    /ItalicAngle 0 def
  99.    /isFixedPitch true def
  100.    /UnderlinePosition 0 def
  101.    /UnderlineThickness 0 def
  102.  
  103.    end            % FontInfo
  104.  
  105.    /FontName fullname cvn def
  106.    /Encoding encoding def
  107.    /PaintType 0 def
  108.    /FontType 1 def
  109.    /FontMatrix [.001 0 0 .001 0 -0.16] readonly def
  110.    /UniqueID UniqueID def
  111.    /FontBBox [0 0 1000 1000] readonly def
  112.  
  113.    /Private 20 dict def
  114.    Private begin
  115.  
  116.    /-| {string currentfile exch readstring pop} readonly def
  117.    /|- {readonly def} readonly def
  118.    /| {readonly put} readonly def
  119.    /BlueValues [] readonly def
  120.    /OtherBlues [] readonly def
  121.    /MinFeature {16 16} readonly def
  122.    /StdHW StdHW def
  123.    /StdVW StdVW def
  124.    /ForceBold false def
  125.    /password 5839 def
  126.    /UniqueID UniqueID def
  127.    /OtherSubrs [] readonly def
  128.    /Subrs [
  129.      (\020\2771p|\020\024\020=-\223D\\\342R) readonly
  130.      (\020\2771py\274\366Uz) readonly
  131.      (\020\2771py\275\304\236i) readonly
  132.      (\020\2771p\371) readonly
  133.      (\020\2771p~\266+6\034\3446z) readonly
  134.    ] readonly def
  135.  
  136.    end            % Private
  137.  
  138.    /CharStrings 256 dict def
  139.    chars
  140.     { exch =string cvs
  141.       dup 0 get highcode eq
  142.        { 1 get encoding exch get exch CharStrings 3 1 roll put }
  143.        { pop pop }
  144.       ifelse
  145.     }
  146.    forall
  147.  
  148.    end            % Font
  149.  
  150.    Font /FontName get Font definefont setfont
  151.    (%stdout) (w) file writefont
  152.  } bind def
  153.  
  154. % Scan the command line and process files.
  155. /options mark
  156.   /version { 2 copy get /version exch def 1 add } bind
  157.   /StdHW { 2 copy get cvx exec /StdHW exch def 1 add } bind
  158.   /StdVW { 2 copy get cvx exec /StdVW exch def 1 add } bind
  159.   /UniqueId { 2 copy get cvi /UniqueID exch def 1 add } bind
  160.   /UniqueID 1 index
  161.   /FontBase { 2 copy get /FontBase exch def 1 add } bind
  162.   /StdEnc { /StdEncMode true def } bind
  163.   /CustomEnc { /CustomEncMode true def } bind
  164.   /Binary { /Binary true def } bind
  165.   /noEncrypt { /Encrypt false def } bind
  166. .dicttomark def
  167. /wftopfa        % [(arg1) ...] wftopfa -
  168.  { init dup 0
  169.     { dup 2 index length ge { exit } if
  170.       2 copy get exch 1 add exch
  171.       options 1 index .knownget { exch pop exec } { readdefs } ifelse
  172.     }
  173.    loop pop pop
  174.    wrfont_dict /binary_CharStrings Binary put
  175.    wrfont_dict /eexec_encrypt Encrypt put
  176.    wrfont_dict /name_all_Encodings CustomEncMode put
  177.    writepfa
  178.  } bind def
  179.  
  180. end                % wftopfa_dict
  181.  
  182. /wftopfa
  183.  { mark exch wftopfa_dict begin /saved save def { wftopfa } exec false%stopped
  184.     { cleartomark true } { cleartomark false } ifelse
  185.    saved end restore { stop } if
  186.  } bind def
  187.  
  188. [ shellarguments
  189.  { ] wftopfa }
  190.  { pop }
  191. ifelse
  192.  
  193. % ---------------- Root font ---------------- %
  194.  
  195. % Define the Encoding for the root font.
  196. /wfrootencoding
  197. % \x00-\x3F
  198.   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
  199.   0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
  200.   0  1  2  3  4  5  6  7  8  0  0  0  0  0  0  0
  201.   9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
  202. % \x40-\x7F
  203.  25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  204.  41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  205.  57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  206.  73 74 75 76 77  0  0  0  0  0  0  0  0  0  0  0
  207. % \x80-\xFF
  208. 128 copy
  209. 256 packedarray def
  210.  
  211. % Define the template for the root font dictionary.
  212. /wfrootfontdict mark
  213.   /FontType 0
  214.   /FontMatrix [1 0 0 1 0 0]
  215.   /FMapType 2
  216.   /Encoding wfrootencoding
  217. .dicttomark def
  218.  
  219. % Define a dummy (placeholder) Type 1 font for the FDepVector.
  220. /type1dummyfont        % <fontname> type1dummyfont <font>
  221.  { mark /FontName 3 -1 roll
  222.    /FontType 1
  223.    /FontMatrix [.001 0 0 .001 0 0]
  224.    /FontBBox [0 0 1000 1000]
  225.    /Encoding /KanjiSubEncoding findencoding
  226.    /CharStrings 0 dict
  227.    /Private mark /BlueValues [] /password 5839 .dicttomark
  228.    .dicttomark dup /FontName get exch definefont
  229.  } bind def
  230.  
  231. % Write a root font.  Again, wrfont.ps does most of the work.
  232. /makerootfont        % <rootname> makerootfont <font>
  233.  { wfrootfontdict dup length 4 add    % FontName, FDepVector, PrefEnc, FID
  234.    dict copy begin
  235.    cvlit /FontName exch def
  236.    4 dict begin
  237.    /len FontName length def
  238.    /str len 4 add string def
  239.    FontName str cvs pop
  240.    str len (.r) putinterval
  241.    /FDepVector [ 16#21 1 16#74
  242.     { dup wfrootencoding exch get 0 eq
  243.        { pop
  244.        }
  245.        { 16 str len 2 add 2 getinterval cvrs pop
  246.          str cvn type1dummyfont
  247.        }
  248.       ifelse
  249.     }
  250.    for end counttomark -1 roll dup counttomark 2 roll
  251.    ] def
  252.    FontName currentdict end definefont
  253.  } bind def
  254. /writerootfont        % <rootname> writerootfont -
  255.  { save exch makerootfont setfont (%stdout) (w) file writefont restore
  256.  } bind def
  257.  
  258. % ---------------- Converting entire fonts ---------------- %
  259.  
  260. % Define the directory where the Wadalab fonts are stored.
  261. /wfdir (/home/ghost/kanji/w) def
  262.  
  263. % Convert an entire Wadalab font.
  264. /writeentirefont    % <fontname> <template*> writeentirefont -
  265.  { 2 dict begin
  266.    /templates exch def
  267.    /fontname exch def
  268.    [ templates
  269.       { wfdir (/) concatstrings exch concatstrings { copystring }
  270.     100 string filenameforall
  271.       }
  272.      forall
  273.      wfdir (/wadalab-sym/*.ps) concatstrings { copystring }
  274.        100 string filenameforall
  275.    ]
  276.    (%!\n) print
  277.     { /currentuserparams where
  278.        { pop currentuserparams /VMReclaim get -2 vmreclaim { vmreclaim } }
  279.        { { } }
  280.       ifelse
  281.     } == (exec\n) print
  282.    (/KanjiSubEncoding ) print /KanjiSubEncoding findencoding ==
  283.      (readonly def\n) print
  284.     { (%stderr) (w) file dup 2 index write== flushfile
  285.        mark exch (CustomEnc) (Binary) (noEncrypt)
  286.        (FontBase) fontname counttomark -1 roll ] wftopfa
  287.     }
  288.    forall
  289.    fontname cvn writerootfont
  290.    (exec\n) print
  291.    end
  292.  } def            % don't bind, so we can print the procedure
  293.  
  294. % Convert the Wadalab JIS 1&2 SaiMincho font.
  295. % To invoke this from the command line,
  296. %    gs -dNODISPLAY -q wftopfa.ps -c writeSaiMincho0 flush quit >wmin0.ps
  297. % To make the resulting font loadable on demand, add to the Fontmap file:
  298. %    /Wadalab-SaiMincho (wmin0.ps) ;
  299. /writeSaiMincho0
  300.  { (Wadalab-SaiMincho) [ (wadalab-mincho-0-8/*.ps) ] writeentirefont
  301.  } bind def
  302.